// Copyright 2022 jeff.li. and/or its affiliates.


#include <tbir/runtime/container.h>
#include <tbir/runtime/container_private.h>
#include <tbir/runtime/ft_container.h>
#include <tbir/runtime/registry.h>

namespace tbir::runtime {

    TBIR_REGISTER_GLOBAL("runtime.UserData").set_body([](PyArgs args) -> RTValue {
        MXCHECK(args.size() == 0) << "[runtime.UserData] no need argument";
        return UserDataRef();
    });

    TBIR_REGISTER_GLOBAL("runtime.UserData___getattr__").set_body([](PyArgs args) -> RTValue {
        MXCHECK(args.size() == 2) << "[runtime.UserData] __getattr__ need 2 arguments, but get "
                                  << args.size();
        auto ud = args[0].AsObjectView<UserDataRef>();
        auto name = args[1].As<string_view>();
        return ud.data().__getattr__(name);
    });

    TBIR_REGISTER_GLOBAL("runtime.UserData___call__").set_body([](PyArgs args) -> RTValue {
        MXCHECK(args.size() >= 1) << "[runtime.UserData] __call__ need 1 or more arguments, but get "
                                  << args.size();
        auto ud_view = args[0].AsObjectView<UserDataRef>();
        return ud_view.data().generic_call(PyArgs(args.begin() + 1, args.size() - 1));
    });

}  // namespace tbir::runtime
